package com.atguigu.gulimall.order.vo;

import lombok.Data;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 订单确认页
 */
@Data
public class OrderConfirmVo {
    //用户收货地址列表 ums_member_receive_address
    private List<MemberAddressVo> address;

    //所有选中的购物项
    private List<OrderItemVo> items;

    //优惠券信息...
    //积分
    private Integer integration;

    private Map<Long,Boolean> stocks;
    //发票记录...

    //防重令牌
    private String orderToken;

    //订单总额
    public BigDecimal getTotal() {
        BigDecimal sum = BigDecimal.ZERO;
        if (items != null) {
            for (OrderItemVo item : items) {
                BigDecimal decimal = item.getPrice().multiply(new BigDecimal(item.getCount()));
                sum = sum.add(decimal);
            }
        }
        return sum;
    }

    //应付价格
    public BigDecimal getPayPrice() {
        return this.getTotal();
    }

    //总件数
    public Integer getCount() {
        int sum = 0;
        if (items != null) {
            for (OrderItemVo item : items) {
                sum += item.getCount();
            }
        }
        return sum;
    }
}
